package com.itcanteen.medical.docker.controller;

import com.itcanteen.medical.common.exception.AdException;
import com.itcanteen.medical.common.vo.CommonResponse;
import com.itcanteen.medical.docker.entity.FundAccount;
import com.itcanteen.medical.docker.service.FundAccountService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/fund")
public class FundAccountController {

    @Autowired
    private FundAccountService fundAccountService;


    @GetMapping("/findOne/{userid}")
    public FundAccount findOne(@PathVariable("userid") long userid){

        System.out.println(userid);
        FundAccount fundAccount = fundAccountService.findOne(userid);

        return fundAccount;
    }

    @GetMapping("/upd/{userid}/{price}")
    public CommonResponse upd(@PathVariable("userid") long userid,@PathVariable("price") Double price){

       CommonResponse commonResponse = fundAccountService.upd(userid,price);


       return commonResponse;
    }

    /**
     * 发送验证码
     * @param phone
     * @return
     */
    @GetMapping("/sendMsg/{phone}")
    @ApiOperation("提现成功提醒")
    public CommonResponse sendCode(@PathVariable("phone")String phone){
        return fundAccountService.sendMsg(phone);
    }

    /**
     * 注销账号功能
     *
     * @return
     */
    @GetMapping("/log/{id}")
    @ApiOperation("账户注销")
    public CommonResponse logOut(@PathVariable("id") Long id) {
        return fundAccountService.logOut(id);
    }


    /**
     * 获取验证码
     */
    @GetMapping("/verify/{phone}")
    @ApiOperation("获取验证码")
    public CommonResponse verify(@PathVariable("phone")String  phone){
        return fundAccountService.verify(phone);
    }


    /**
     * 找回账号功能
     * @return
     */
    @GetMapping("/retrieve/{phone}/{code}")
    @ApiOperation("账号找回")
    public CommonResponse retrieve(@PathVariable("phone")String  phone, @PathVariable("code")String  code) throws AdException {
        return fundAccountService.retrieveAccount(phone,code);
    }
}
